package com.hhkj.admin.course.domain;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ruoyi.common.core.domain.BizBaseEntity;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import com.ruoyi.common.valid.VAdd;
import com.ruoyi.common.valid.VEdit;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * 课程价格默认题库的价格套餐
 * @TableName s_course_price_conf
 */
@TableName(value ="s_course_price_conf")
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CoursePriceConf extends BizBaseEntity{

    /**
     * 天数
     */
    @TableField(value = "day_amount")
    @NotNull(message = "天数不能为空", groups = {VEdit.class, VAdd.class})
    @Min(message = "天数不能小于0", value = 0, groups = {VEdit.class, VAdd.class})
    private Integer dayAmount;

    /**
     * 价格
     */
    @TableField(value = "price")
    @NotNull(message = "价格不能为空", groups = {VEdit.class, VAdd.class})
    @Min(message = "价格不能小于0", value = 0, groups = {VEdit.class, VAdd.class})
    private BigDecimal price;

    /**
     * 课程id，关联s_course
     */
    @TableField(value = "course_id")
    @NotNull(message = "科目id不能为空", groups = {VAdd.class})
    private Long courseId;

    public void setPrice(BigDecimal price) {
        if (ObjectUtil.isNotEmpty(price)) {
            this.price = price.setScale(0, BigDecimal.ROUND_DOWN);
        }
    }
}